package com.medication.config;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.medication.model.SecAdminUser;
import com.medication.utils.Currents;

/**
 * @author heem
 * @create time 创建时间：2016年5月27日 下午3:43:16
 * @version 1.0
 * @since
 */
public class GlobalActionInterceptor implements Interceptor {

	@Override
	public void intercept(Invocation inv) {
		if (inv.isActionInvocation()) {
			String actionKey = inv.getActionKey();
			if (actionKey.indexOf("login") != -1 || actionKey.indexOf("tester") != -1) {
				inv.invoke();
				return;
			} else {
				// 判断登录用户
				SecAdminUser adminUser = (SecAdminUser) inv.getController().getSessionAttr(Currents.CURRENT_USER);
				if (adminUser == null) {
					inv.getController().redirect("/admin/login/index");
				} else {
					inv.getController().setAttr(Currents.CURRENT_USER, adminUser);
					inv.invoke();
				}
			}
		}
	}

}
